Determine whether a link points to a file on local host or foreign domain [migrated]

Posted by user107157 on Programmers See other posts from Programmers or by user107157
Published on 2013-11-07T18:00:13Z Indexed on 2013/11/07 22:19 UTC
Read the original article Hit count: 438

Filed under:

This has been a burning question for me ever since and I think it's interesting enough to discuss it on the forums. As most will know, in websites we include anchor links, stylesheets, script files (javascript) and images. For anchor links we use the form <a href="..." />
For stylesheets we may use the form <link rel="stylesheet" type="text/css" href="..." />
For javascript we may use <script src="..." />
For images we use <img src="..." />

So, the question is this:

How do we know that what is in the link pointer (i.e. replacing the ... in each example) is a local file or a foreign entity?

To make it clear, lets say I create a local file named "ashish.com". Now, my purpose is to create a link so that anybody who clicks on it may download it. So, my code would be thus:

<a href="ashish.com">Download It</a>

But this makes it ambiguous. I could also be referring to a website named "ashish.com" So, how does the computer magically know which one I mean? Or does it even know this? What would happen in such a scenario?

© Programmers or respective owner

Related posts about websites